﻿using System.Collections.Generic;

namespace CardPlay.Model.ActionModel
{
    public class ComplexAction : IAction, IEnumerable<IAction>
    {
        private readonly List<IAction> _actions = new List<IAction>();

        public ComplexAction()
        {
            
        }

        public ComplexAction(IEnumerable<IAction> actions)
        {
            _actions.AddRange(actions);
        }
        
        public void Add(IAction action)
        {
            _actions.Add(action);
        }
    
        #region IAction Members

        void IAction.Execute()
        {
            foreach (var action in _actions)
                action.Execute();
        }

        void IAction.Reverse()
        {
            for (var i = _actions.Count; --i >= 0;)
                _actions[i].Reverse();
        }

        #endregion
        
        public IEnumerator<IAction> GetEnumerator()
        {
            return _actions.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _actions.GetEnumerator();
        }
    }
}
